package com.gateway.video.rtsp;

import com.gateway.video.rtsp.bootstrap.VideoBootstrap;
import com.gateway.video.rtsp.channel.DefaultInitChannel;
import com.gateway.video.rtsp.channel.InitChannel;
import com.gateway.video.rtsp.config.VideoConfig;
import com.gateway.video.rtsp.handler.RtspServerHandler;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;

@EnableConfigurationProperties(VideoConfig.class)
public class VideoConfiguration {
    @Bean
    public VideoBootstrap videoServerBootstrap() {
        return new VideoBootstrap();
    }

    @Bean
    public InitChannel initChannel() {
        return new DefaultInitChannel();
    }

    @Bean
    public EventLoopGroup eventLoopGroup() {
        return new NioEventLoopGroup(0, new ThreadFactoryBuilder().setNameFormat("video-rtsp-worker-pool-%s").build());
    }

    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public RtspServerHandler rtspServerHandler() {
        return new RtspServerHandler();
    }
}
